#include<iostream.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

// converts hexadecimal value to decimal and perform the operation
// specified by the char c with the decimal value n and the result
//of operation is obtained from the input string(alias).
void hex(char in[],char c,int &n)
{
  int i,j,len,factor=1;
  int val=0,tmp;
  char ret[10];

  len=strlen(in);

  for(i=len;i>=0;i--)
  {
   switch(in[i])
   { case'0':{ tmp=0*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'1':{ tmp=1*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'2':{ tmp=2*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'3':{ tmp=3*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'4':{ tmp=4*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'5':{ tmp=5*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'6':{ tmp=6*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'7':{ tmp=7*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'8':{ tmp=8*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'9':{ tmp=9*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'a':
     case'A':{ tmp=10*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'b':
     case'B':{ tmp=11*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'c':
     case'C':{ tmp=12*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'd':
     case'D':{ tmp=13*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'e':
     case'E':{ tmp=14*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
     case'f':
     case'F':{ tmp=15*factor;
	       val+=tmp;
	       factor*=16;
	       break;
	       }
    }//switch
  }//for
   switch(c)
   {case '+': val+=n;
	      break;
    case '-': val-=n;
	      break;
    case ' ': break;
   }//switch



   n=val;
   itoa(val,ret,16);
   strcpy(in,ret);


}// end of hex







/*void main()
{


int i=0;
char str[10];
clrscr();
strcpy(str,"163");
hex(str,'+',i);
cout<<str;
cout<<" \n"<<i;
getch();


}
*/

